// 首字母大写
import { Constants } from '../constants/constants';

export function capitalizeFirstLetter(value: string) {
  return value.charAt(0).toUpperCase() + value.slice(1);
}

// 内链域名特殊字符替换
export function innerLinkReplaceEach(path: string) {
  return replaceEach(
    path,
    [Constants.HTTP, Constants.HTTPS, Constants.WWW, '.'],
    ['', '', '', '/'],
  );
}
function replaceEach(
  searchText: string,
  searchArray: string | any[],
  replaceArray: any[],
) {
  // 使用 map() 函数将 searchArray 中的每个元素替换为 replaceArray 中对应位置的元素
  let result = searchText;
  for (let i = 0; i < searchArray.length; i++) {
    result = result.split(searchArray[i]).join(replaceArray[i]);
  }
  return result;
}
